package com.fly.video.downloader.database;

import ohos.app.Context;
import ohos.data.DatabaseHelper;
import ohos.data.rdb.RdbOpenCallback;
import ohos.data.rdb.RdbStore;
import ohos.data.rdb.StoreConfig;

public class HistoryDBHelper {
    public static RdbStore store=null;
    public static String DB_NAME="history";
    public static RdbStore getIntance(Context context){
        if(store==null){
            StoreConfig config = StoreConfig.newDefaultConfig("downloader.db");
            DatabaseHelper helper = new DatabaseHelper(context);
            store = helper.getRdbStore(config, 1, new RdbOpenCallback() {
                @Override
                public void onCreate(RdbStore rdbStore) {
                    rdbStore.executeSql("CREATE TABLE IF NOT EXISTS "+DB_NAME+" (id INTEGER primary key autoincrement, vid text, className text, json text, created_at INTEGER)");
                }
                @Override
                public void onUpgrade(RdbStore rdbStore, int i, int i1) {

                }
            }, null);
        }
        return store;
    }
}
